package com.shengqin.controller;

import com.shengqin.common.pojo.CommonResult;
import com.shengqin.entity.PlanReservationItem;
import com.shengqin.service.IPlanReservationItemService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/admin/v1/reservation/item")
public class PlanReservationItemController {

    @Resource
    private IPlanReservationItemService reservationItemService;

    @PostMapping("save")
    public CommonResult<Boolean> onSave(@RequestBody PlanReservationItem reservationItem){
        if (reservationItem.getId() == null) {
            reservationItem.setCreateTime(LocalDateTime.now());
        }
        return CommonResult.data(reservationItemService.saveOrUpdate(reservationItem));
    }

    @PostMapping("listByPlanId")
    public CommonResult<List<PlanReservationItem>> listByPlanId(@RequestBody PlanReservationItem reservationItem){
        return CommonResult.data(reservationItemService.listByPlanId(reservationItem));
    }

}
